package com.ctshk.rpc.order.tour.util;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Random;

public class Utils {

    public static final String yyMMdd = "yyMMdd";
    public static final String HHmmss = "HHmmss";
    public static final String HH_mm_ss = "HH:mm:ss";
    public static final String yyyyMMdd = "yyyyMMdd";
    public static final String yyyy_MM_dd = "yyyy-MM-dd";
    public static final String yyMMddHHmmss = "yyMMddHHmmss";
    public static final String DECIMAL_POINT4 = ".####";

    /**
     * 获取随机数2
     */
    public static String getRandom2() {
        Random random = new Random();
        int ends = random.nextInt(99);
        return String.format("%02d", ends);
    }

    /**
     * 获取随机数6
     */
    public static String getRandom6() {
        Random random = new Random();
        int ends = random.nextInt(999999);
        return String.format("%06d", ends);
    }

    /**
     * 获取随机数6
     */
    public static String getRandom3() {
        Random random = new Random();
        int ends = random.nextInt(999);
        return String.format("%03d", ends);
    }



    /**
     * 获取星期几
     */
    public static String getWeekOfDate(LocalDateTime now) {
        String[] weekDays = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};
        return weekDays[now.getDayOfWeek().getValue()];
    }

    /**
     * 获取日期字符串
     */
    public static String getDateString(LocalDate now, String format) {
        return now.format(DateTimeFormatter.ofPattern(format));
    }

    /**
     * 获取日期字符串
     */
    public static String getDateString(LocalDateTime now, String format) {
        return now.format(DateTimeFormatter.ofPattern(format));
    }

    /**
     * 获取日期和星期几
     */
    public static String getDayAndWeek(LocalDateTime now) {
        return now.format(DateTimeFormatter.ofPattern(yyyyMMdd)) + " " + Utils.getWeekOfDate(now);
    }




    public static LocalDateTime asLocalDateTime(Date date) {
        return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
    }

    public static LocalDate asLocalDateForString(String date) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern(yyyy_MM_dd);
        return LocalDate.parse(date, fmt);
    }

    /**
     * 获取收据订单号（保险）
     */
    public static String getReceiptNumberB() {
        //TODO 門市編號+員工編號+年後2位+月日4位+B+時分秒6位+（S）
        LocalDateTime now = LocalDateTime.now();
        return now.format(DateTimeFormatter.ofPattern(yyMMdd)) + "B" + now.format(DateTimeFormatter.ofPattern(HHmmss)) + getRandom6() + "（S）";
    }

}
